cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
project(search_engine VERSION 0.0.1 LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)

set(RESOURCE_DIR "${CMAKE_SOURCE_DIR}/resources")

include_directories(
    ${CMAKE_CURRENT_SOURCE_DIR}/include
    ${CMAKE_CURRENT_SOURCE_DIR}/include/external
)

# 查找GTest库
find_package(GTest REQUIRED)

add_library(${PROJECT_NAME} STATIC
    src/directory_scanner.cpp
    src/keyword_processor.cpp
    src/page_processor.cpp

    src/util/protocol.cpp
    src/search/search_server.cpp
    src/search/keyword_recommend.cpp
    src/search/page_search.cpp

    src/reactor/epoll.cpp
    src/reactor/channel.cpp
    src/reactor/buffer.cpp
    src/reactor/event_loop.cpp
    src/reactor/event_loop_thread.cpp
    src/reactor/event_loop_threadPool.cpp
    src/reactor/acceptor.cpp
    src/reactor/tcp_connection.cpp
    src/reactor/tcp_server.cpp
)

# 链接项目依赖库
target_link_libraries(${PROJECT_NAME} PRIVATE
    tinyxml2
)

# 测试目标配置
add_executable(test_dirScan test/test_dirScan.cpp)
# 链接GTest和项目库
target_link_libraries(test_dirScan PRIVATE
    ${PROJECT_NAME}
)

add_executable(test_keyword_processor test/test_keyword_processor.cpp)
target_link_libraries(test_keyword_processor PRIVATE
    ${PROJECT_NAME}
)

add_executable(process_data src/process_data.cpp)
target_link_libraries(process_data PRIVATE
    ${PROJECT_NAME}
)

# --- 主程序 ---
add_executable(search_server_main src/main.cpp)
target_link_libraries(search_server_main PRIVATE ${PROJECT_NAME})

# --- 测试客户端 ---
add_executable(client_test test/client_test.cpp src/util/protocol.cpp)
